$(document).ready(function(){
		 function myadd(obj,e,fn){
			if(obj.attachEvent){
				obj.attachEvent("on"+e, fn);
			}else{
				obj.addEventListener(e,fn,false);
			}
		}
		var wFlag = false;
		var cont = document.getElementById("contents");
	

		function cleearAni(){
			
			$(".fadeInDown,.fadeInUp,.rollIn,.bounceInLeft,.bounceInUp,.bounceInRight,.bounceInDown,.a-bounce,.a-flip,.a-flash,.a-shake,.a-swing,.a-wobble,.a-ring,.a-fadein,.a-fadeinT,.a-fadeinR,.a-fadeinB,.a-fadeinL,.a-bouncein,.a-bounceinT,.a-bounceinR,.a-bounceinB,.a-bounceinL,.a-rotatein,.a-rotateinLT,.a-rotateinLB,.a-rotateinRT,.a-rotateinRB,.a-flipin,.a-flipinX,.a-flipinY,.a-fadeout,.a-fadeoutT,.a-fadeoutR,.a-fadeoutB,.a-fadeoutL,.a-bounceout,.a-bounceoutT,.a-bounceoutR,.a-bounceoutB,.a-bounceoutL,.a-rotateout,.a-rotateoutLT,.a-rotateoutLB,.a-rotateoutRT,.a-rotateoutRB,.a-flipout,.a-flipoutX,.a-flipoutY").removeClass("cur")
			
		}
		function addAni(obj){
			$(obj).find(".fadeInDown,.fadeInUp,.rollIn,.bounceInLeft,.bounceInUp,.bounceInRight,.bounceInDown,.a-bounce,.a-flip,.a-flash,.a-shake,.a-swing,.a-wobble,.a-ring,.a-fadein,.a-fadeinT,.a-fadeinR,.a-fadeinB,.a-fadeinL,.a-bouncein,.a-bounceinT,.a-bounceinR,.a-bounceinB,.a-bounceinL,.a-rotatein,.a-rotateinLT,.a-rotateinLB,.a-rotateinRT,.a-rotateinRB,.a-flipin,.a-flipinX,.a-flipinY,.a-fadeout,.a-fadeoutT,.a-fadeoutR,.a-fadeoutB,.a-fadeoutL,.a-bounceout,.a-bounceoutT,.a-bounceoutR,.a-bounceoutB,.a-bounceoutL,.a-rotateout,.a-rotateoutLT,.a-rotateoutLB,.a-rotateoutRT,.a-rotateoutRB,.a-flipout,.a-flipoutX,.a-flipoutY").addClass("cur")
		}
		function setRightdao(num){
			var x= "eq"+num;
			$(".nav ul li").removeClass("cur")
			$(".rightdao span").removeClass("cur")
			$(".nav ul li").eq(num).addClass("cur")
			$(".rightdao span").eq(num).addClass("cur")
		}
		var h = document.documentElement.clientHeight || document.body.clientHeight;
		var scrollTop = document.documentElement.scrollTop ||  document.body.scrollTop;
		var bg0Top = $('.section').eq(0).offset().top;
		var bg1Top = $('.section').eq(1).offset().top;
		var bg2Top = $('.section').eq(2).offset().top;
		var bg3Top = $('.section').eq(3).offset().top;
		var bg4Top = $('.section').eq(4).offset().top;
		var bg5Top = $('.section').eq(5).offset().top;
		var bg6Top = $('.section').eq(6).offset().top;
		var bg7Top = $('.section').eq(7).offset().top;
		var bg8Top = $('.section').eq(8).offset().top;
		
		$(".section").each(function(i){
			var stx = "bg"+i+"top";
			stx = $('.section').eq(i).offset().top
		})
		
		function rightDian(num){
			var xm = null;
			switch(num){
				case 0: xm = bg0Top;break;
				case 1: xm = bg1Top;break;
				case 2: xm = bg2Top;break;
				case 3: xm = bg3Top;break;
				case 4: xm = bg4Top;break;
				case 5: xm = bg5Top;break;
				case 6: xm = bg6Top;break;
				case 7: xm = bg7Top;break;
			}
			vgTop = xm;
			cleearAni();
			addAni( $('.section').eq(num));
			
			$(".nav ul li").removeClass("cur")
			$(".rightdao span").removeClass("cur")
			$(".nav ul li").eq(num).addClass("cur")
			$(".rightdao span").eq(num).addClass("cur")
			$('html,body').animate({scrollTop: xm},vgTime,function(){})
		}
		
		$(".nav ul li").click(function(){
			var x = $(".nav ul li").index(this);
			rightDian(x)
		})
		$(".rightdao span").click(function(){
			var x = $(".rightdao span").index(this);
			rightDian(x)
		})
		var vgTop = scrollTop;
		var vgTime = 300;
		var maTime = 500;
		var stTime = 50;
		
		if(vgTop >= 0 && vgTop < bg1Top){
			cleearAni()
			addAni(".section:eq(0)")
			setRightdao(0)
			vgTop = 0;
			$('html,body').animate({scrollTop: 0},vgTime,function(){})
		}else if(vgTop>= bg1Top &&　vgTop <bg2Top){
			cleearAni()
			addAni(".section:eq(1)")
			setRightdao(1)
			vgTop =bg1Top
			$('html,body').animate({scrollTop: bg1Top},vgTime,function(){})
		}else if(vgTop>= bg2Top && vgTop < bg3Top){
			cleearAni()
			addAni(".section:eq(2)")
			setRightdao(2)
			vgTop =bg2Top
			$('html,body').animate({scrollTop: bg2Top},vgTime,function(){})
		}else if(vgTop >=bg3Top && vgTop < bg4Top) {
			cleearAni()
			addAni(".section:eq(3)")
			setRightdao(3)
			vgTop =bg3Top
			$('html,body').animate({scrollTop: bg3Top},vgTime,function(){})
		}else if(vgTop >=bg4Top && vgTop < bg5Top) {
			cleearAni()
			addAni(".section:eq(4)")
			setRightdao(4)
			vgTop =bg4Top
			$('html,body').animate({scrollTop: bg4Top},vgTime,function(){})
		}else if(vgTop >=bg5Top && vgTop < bg6Top) {
			cleearAni()
			addAni(".section:eq(5)")
			setRightdao(5)
			vgTop =bg5Top
			$('html,body').animate({scrollTop: bg5Top},vgTime,function(){})
		}else if(vgTop >=bg6Top && vgTop < bg7Top) {
			cleearAni()
			addAni(".section:eq(6)")
			setRightdao(6)
			vgTop =bg5Top
			$('html,body').animate({scrollTop: bg6Top},vgTime,function(){})
		}else if(vgTop >=bg7Top) {
			cleearAni()
			addAni(".section:eq(7)")
			setRightdao(7)
			vgTop =bg6Top
			$('html,body').animate({scrollTop: bg7Top},vgTime,function(){})
		}
		
		myadd(cont,'mousewheel',function(e){
			
			var e = e || event;
			var absDetail = Math.abs(e.detail);
			if(absDetail){
				e.preventDefault();
				//document.body.style.overflowY = "hidden";
			}
			/* document.body.onmousewheel = window.onmousewheel = function(){
				return false;
			}; */
			if(e.wheelDelta > 0 || e.detail < 0){
				wFlag = true; 
			}else if(e.wheelDelta<0 || e.detail > 0){
				wFlag = false;
			}
			var sTop = $(window).scrollTop();
			var st = sTop+h;
			if(!wFlag){
				if(!$('html,body').is(":animated")){
					if(vgTop == 0){
						cleearAni()
						addAni(".section:eq(1)")
						setRightdao(1)
						$('html,body').animate({scrollTop: bg1Top},vgTime,function(){})
						
						vgTop = bg1Top;
					}else if(vgTop == bg1Top){
						cleearAni()
						addAni(".section:eq(2)")
						setRightdao(2)
						$('html,body').animate({scrollTop: bg2Top},vgTime,function(){
						})
						vgTop = bg2Top;
					}else if(vgTop == bg2Top){
						cleearAni()
						addAni(".section:eq(3)")
						setRightdao(3)
						$('html,body').animate({scrollTop: bg3Top},vgTime,function(){})
						vgTop = bg3Top;
					}else if(vgTop == bg3Top){
						cleearAni()
						addAni(".section:eq(4)")
						setRightdao(4)
						$('html,body').animate({scrollTop: bg4Top},vgTime,function(){
						
						})
						vgTop = bg4Top;
					}else if(vgTop == bg4Top){
						cleearAni()
						addAni(".section:eq(5)")
						setRightdao(5)
						$('html,body').animate({scrollTop: bg5Top},vgTime,function(){
						
						})
						vgTop = bg5Top;
					}else if(vgTop == bg5Top){
						cleearAni()
						addAni(".section:eq(6)")
						setRightdao(6)
						$('html,body').animate({scrollTop: bg6Top},vgTime,function(){
						
						})
						vgTop = bg6Top;
					}else if(vgTop == bg6Top){
						cleearAni()
						addAni(".section:eq(7)")
						setRightdao(7)
						$('html,body').animate({scrollTop: bg7Top},vgTime,function(){
						
						})
						vgTop = bg7Top;
					}else if(vgTop == bg7Top){
						cleearAni()
						addAni(".section:eq(8)")
						setRightdao(8)
						$('html,body').animate({scrollTop: bg8Top},vgTime,function(){
						
						})
						vgTop = bg8Top;
					}
					return false;
				}
			}
			if(wFlag){	
				if(!$('html,body').is(":animated")){
					if(vgTop == bg1Top){
						cleearAni()
						addAni(".section:eq(0)")
						setRightdao(0)
						$('html,body').animate({scrollTop: 0},vgTime,function(){})
						vgTop = 0;
					}else if(vgTop == bg2Top){
						cleearAni()
						addAni(".section:eq(1)")
						setRightdao(1)
						$('html,body').animate({scrollTop: bg1Top},vgTime,function(){})
						
						vgTop = bg1Top;
					}else if(vgTop == bg3Top){
						cleearAni()
						addAni(".section:eq(2)")
						setRightdao(2)
						$('html,body').animate({scrollTop: bg2Top},vgTime,function(){
						})
						vgTop = bg2Top;
					}else if(vgTop == bg4Top){
						cleearAni()
						addAni(".section:eq(3)")
						setRightdao(3)
						$('html,body').animate({scrollTop: bg3Top},vgTime,function(){
						})
						
						vgTop = bg3Top;
					}else if(vgTop == bg5Top){
						cleearAni()
						addAni(".section:eq(4)")
						setRightdao(4)
						$('html,body').animate({scrollTop: bg4Top},vgTime,function(){
						})
						
						vgTop = bg4Top;
					}else if(vgTop == bg6Top){
						cleearAni()
						addAni(".section:eq(5)")
						setRightdao(5)
						$('html,body').animate({scrollTop: bg5Top},vgTime,function(){
						})
						
						vgTop = bg5Top;
					}else if(vgTop == bg7Top){
						cleearAni()
						addAni(".section:eq(6)")
						setRightdao(6)
						$('html,body').animate({scrollTop: bg6Top},vgTime,function(){
						})
						
						vgTop = bg6Top;
					}else if(vgTop == bg8Top){
						cleearAni()
						addAni(".section:eq(7)")
						setRightdao(7)
						$('html,body').animate({scrollTop: bg7Top},vgTime,function(){
						})
						
						vgTop = bg7Top;
					}
					return false;
				}
			}
		})
		
		
		
		$(window).scroll(function(){
			var sc = $(window).scrollTop();
			if(sc >=150){
				$(".nav").addClass("cur")
			}else{
				$(".nav").removeClass("cur")
			}
		})
});